<template>
	<view class="" style="overflow: hidden;">
		<view class="left" @tap.stop="back">
			<image src="@/static/home/left.png" mode=""></image>
		</view>
		<view class="textName">
			密码设置
		</view>
		<view class="form">
			<view class="list flex-r-b-c">
				<view class="text">旧密码:</view>
				<input password type="text" placeholder="请输入旧密码" v-model="form.oldCode" />
			</view>
			<view class="list flex-r-b-c">
				<view class="text">新密码:</view>
				<input password type="text" placeholder="请输入新密码" v-model="form.oneCode" />
			</view>
			<view class="list flex-r-b-c">
				<view class="text">确认密码:</view>
				<input  password type="text" placeholder="请再次确认密码" v-model="form.twoCode"/>
			</view>
			<view class="popupBtn"  @tap.stop="editAccount">提交</view>
		</view>
	</view>
</template>

<script>
	// import vvSelect from '@/pages/components/vv-select/vv-select.vue'
	import base from '@/api/base.js'
	export default {
		data() {
			return {
				image: this.$base.smallimgUrl,
				logo:'',
				form: {
					oldCode:'',
					oneCode:'',
					twoCode:''
				},
				isEdit:false,
			};
		},
		// components: {
		// 	vvSelect,
		// },
		onLoad(el) {
			// this.accountCardInfo()
		},
		methods: {
			submit(){
				uni.chooseImage({ // 从本地相册选择图片或使用相机拍照。
					count: 1,//默认选择1张图片
					sizeType: ['original', 'compressed'],//original 原图，compressed 压缩图，默认二者都有
					success:  (res)=> {
						// console.log(res.tempFilePaths[0],'res.tempFilePaths[0]');//成功则返回图片的本地文件路径列表 tempFilePaths
						this.logo = res.tempFilePaths[0]//更新本低浏览头像图片
						this.uploadFilePromise(res.tempFilePaths[0]).then(res=>{
							console.log(res,'哈哈哈')
							this.form.face = res.showUrl
						})
						// console.log(a,)
					}
				});

			},
			uploadFilePromise(avatarUrl) {
				return new Promise((resolve, reject) => {
					let a = uni.uploadFile({
						url: `${base.imgUrl}/common/upload`, // 仅为示例，非真实的接口地址
						filePath: avatarUrl,
						name: 'file',
						formData: {
							user: 'test',
						},
						success: (res) => {
							setTimeout(() => {
								resolve({
									url: JSON.parse(res.data).url,
									showUrl: JSON.parse(res.data).fileName,
								})
							}, 1000)	
						},
						fail(fails) {
							console.log(fails,'fail')
						}
					});
				})
			},
			back() {
				uni.navigateBack({
					delta: 1
				})
			},
			// 编辑卡
			editAccount(){
				let that = this
				// let reg_tel = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/
				if (that.form.oldCode == '') return that.$utils.toast('旧密码不能为空')
				if (that.form.oneCode == '') return that.$utils.toast('新密码不能为空')
				if (that.form.twoCode == '') return that.$utils.toast('请再次确认密码')
				if (that.form.oneCode != that.form.twoCode) return that.$utils.toast('两次密码不一致')
				// if (!reg_tel.test(that.form.mobile)) return that.$utils.toast('请输入正确手机号')
				
				that.$api.updatePwd(that.form.oldCode,that.form.twoCode).then(res => {
					console.log(res.data,'that.res.data')
					if(res.data.code == 200){
						that.$utils.toast('操作成功')
						setTimeout(() => {
							uni.navigateBack()
						},2000)
					}else{
						that.$utils.toast(res.data.msg)
					}
				})
			},
			// 添加卡
			getAccount(){
				let that = this
				let reg_tel = /^([1-9]{1})(\d{14,19})$/
				if (that.form.nickName == '') return that.$utils.toast('请输入昵称')
				if (!reg_tel.test(that.form.mobile)) return that.$utils.toast('请输入正确手机号22')
				// if (that.form.bank_name == '') return that.$utils.toast('请输入银行名称')
				// if (that.form.bank_address == '') return that.$utils.toast('请输入开户行')
				
				that.$api.bindTxAccount({
					name: that.form.name,
					account:that.form.account,
					bank_name:that.form.bank_name,
					bank_address:that.form.bank_address,
				}).then(res => {
					if(res.data.msg == '设置成功'){
						that.$utils.toast(res.data.msg)
						setTimeout(() => {
							uni.navigateBack({
								delta: 1
							})
						},2000)
					}
				})
			},
		}
	}
	
</script>

<style lang="less">	
		
	.uni-page{
		overflow: hidden !important;
	}
	.vv-input__placeholder{
		color: #7F8084 !important;
	}
	.left {
		top: 4%;
		left: 4%;
		position: fixed;
	
		image {
			width: 22rpx;
			height: 36rpx;
		}
	}
	.textName{
		top: 3%;
		left: 41%;
		position: fixed;
		color: #000;
		font-size: 34rpx;
	}
	.form {
		width: 90%;
		margin: 0 auto;
		margin-top: 120rpx;
	
		.list {
			width: 100%;
			height: 110rpx;
			border-bottom: 1px solid #EFEFEF;
	
			.text {
				font-size: 28rpx;
				font-weight: 400;
				color: #000;
			}
	
			input {
				text-align: right;
			}
		
			
			image {
				width: 20rpx;
				height: 12rpx;
				margin: 14rpx;
			}
		}
	
		.default {
			margin-top: 40rpx;
			margin-left: 30rpx;
			font-size: 28rpx;
			color: #7F8084;
			font-weight: 400;
		}
	
		.popupBtn {
			width: 100%;
			height: 96rpx;
			line-height: 96rpx;
			border-radius: 16rpx;
			background-color: #469D96;
			color: #fff;
			font-size: 28rpx;
			font-weight: 500;
			text-align: center;
			margin-top: 200rpx;
		}
	
		.deleteBtn {
			width: 100%;
			height: 96rpx;
			line-height: 96rpx;
			border-radius: 96rpx;
			background-color: #DCDCDC;
			color: #7F8084;
			font-size: 28rpx;
			font-weight: 500;
			text-align: center;
			margin-top: 40rpx;
			margin-bottom: 40rpx;
		}
		.logo{
			image {
				width: 100rpx !important;
				height: 100rpx !important;
				border-radius: 50%;
				margin-bottom: 10rpx;
			}
		}
	}
</style>